package com.nf.health.app.utils;

import android.app.Activity;
import android.content.Context;
import android.text.TextUtils;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.PopupWindow;

import com.nf.health.app.R;
import com.nf.health.app.customview.CustomShareBoard;
import com.umeng.socialize.controller.UMSocialService;
import com.umeng.socialize.media.QQShareContent;
import com.umeng.socialize.media.QZoneShareContent;
import com.umeng.socialize.media.SinaShareContent;
import com.umeng.socialize.media.UMImage;
import com.umeng.socialize.sso.SinaSsoHandler;
import com.umeng.socialize.weixin.media.CircleShareContent;
import com.umeng.socialize.weixin.media.WeiXinShareContent;

/**
 * Created by Administrator on 2017/4/15/015.
 */

public class SharedUtils {
    public static  void setShareContent(UMSocialService mController,  Context context,String  image,String httpUrl,String content,String title) {
        // 配置SSO
        mController.getConfig().setSsoHandler(new SinaSsoHandler());
        UMImage umImage;
        if (TextUtils.isEmpty(image) || image == null) {//判断分享文章中的第一张图片是否为空
            umImage = new UMImage(context, R.drawable.ic_calorie);//赋值默认logo
        } else {
            umImage = new UMImage(context, image);
        }
        String targetUrl = httpUrl;
        String content1 = content;
        // 微信分享必须设置targetURL，需要为http链接格式
        // 微信朋友圈只能显示title，并且过长会被微信截取部分内容
        WeiXinShareContent weixinContent = new WeiXinShareContent();
        weixinContent.setShareContent(content1);
        weixinContent.setTitle(title);
        weixinContent.setTargetUrl(targetUrl);
        weixinContent.setShareMedia(umImage);
        mController.setShareMedia(weixinContent);

        // 设置朋友圈分享的内容
        CircleShareContent circleMedia = new CircleShareContent();
        circleMedia.setShareContent(content1);
        circleMedia.setTitle(title);
        circleMedia.setShareMedia(umImage);
        circleMedia.setTargetUrl(targetUrl);
        mController.setShareMedia(circleMedia);

        QQShareContent qqShareContent = new QQShareContent();
        qqShareContent.setShareContent(content1);
        qqShareContent.setTitle(title);
        qqShareContent.setShareMedia(umImage);
        qqShareContent.setTargetUrl(targetUrl);
        mController.setShareMedia(qqShareContent);
        // 设置QQ空间分享内容
        QZoneShareContent qzone = new QZoneShareContent();
        qzone.setTargetUrl(targetUrl);
        qzone.setShareContent(content1);
        qzone.setTitle(title);
        qzone.setShareMedia(umImage);
        mController.setShareMedia(qzone);
        //新浪微博、腾讯微博及豆瓣的跳转链接只能设置在分享文字之中，以http形式传递即可，人人网可以单独设置跳转链接，方法为：
        SinaShareContent sinaContent = new SinaShareContent();
        sinaContent.setShareContent(title + httpUrl);
        //		sinaContent.setTitle(title);
        sinaContent.setShareImage(umImage);
        mController.setShareMedia(sinaContent);
    }


    public static void configPlatforms(UMSocialService mController, Activity context) {
        // 添加新浪SSO授权
        mController.getConfig().setSsoHandler(new SinaSsoHandler());
        SharePlatform.addQQ_QZonePlatform(context);
        SharePlatform.addWXPlatform(context);
    }

    public static void initCustomShareBoard(Activity context){
        CustomShareBoard shareBoard = new CustomShareBoard(context);
        shareBoard.setInputMethodMode(PopupWindow.INPUT_METHOD_NEEDED);
        //再设置模式，和Activity的一样，覆盖，调整大小。
        shareBoard.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE);
        shareBoard.showAtLocation(context.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
        shareBoard.showAtLocation(context.getWindow().getDecorView(), Gravity.BOTTOM, 0, 0);
    }
}
